<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>日志类别管理</title>
    <link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath }/styles/admin/aCategory.css" />
  </head>
  
  <body>
  	   <jsp:include page="include/header.jsp" flush="true" />
  	   	<script type="text/javascript">
			$("document").ready(function(){
				//添加类别部分
				$(".input").focus(function(){
					$("#addResult").html("");
				});
				$(".submit").click(function(){
					if($(".input").val().length>0){
						var isPhoto=$(".check").attr("checked")=="checked"?1:0;
						$.post("admin/aCategoryAction_saveCategory.action",{"category.cname":$(".input").val(),"category.isPhoto":isPhoto},
								function(data){
									$("#addResult").html(data.result);
								},"json"
						);
					}else{
						$("#addResult").html("请输入有效的数据");
					}
				});
				
				//修改和删除类别部分
				
				//修改部分开始
				$(".update").click(function(){
					var checkBox = $(this).parent().prev().children();
					var cname = $(this).parent().prev().prev();
					var cid = cname.prev().html();
					if($(this).html()=="修改"){
						$(this).html("确定");
						bool = false;
						checkBox.removeAttr("readonly");
						var value = cname.text();
						cname.html("<input type='text' value="+value+" class='value' />");
					}
					else{
						$(this).html("修改");
						checkBox.attr("readonly","readonly");
						var value = cname.children().val();
						cname.html(value);
						var isPhoto=checkBox.attr("checked")=="checked"?1:0;
						$.post("admin/aCategoryAction_updateCategory.action",{"category.cname":value,"category.isPhoto":isPhoto,"category.cid":cid});
					}
					
				});
				//修改部分结束
				
				//删除部分开始
				$(".delete").click(function(){
					var value =$(this).parent().prev().prev().prev().html(); 
					var cid = $(this).parent().prev().prev().prev().prev().html();
					var choice=confirm("您确认要删除 "+value+" 类别吗？", function() { }, null);
					if(choice){
						$(this).parent().parent().remove();
						$.post("admin/aCategoryAction_deleteCategory.action",{"category.cid":cid});
					}
				});
				//删除部分结束
				
			});
		</script>
        <div id="right">
        	<h1> </h1>
            <div id="right_main">
            	<div style="text-align:center;"><h2>类别管理</h2></div>
            	<div id="addC">
            		<form>
            			类别名：<input type="text" name="category.cname" class="input"   /><br/>
            			是否为图片类：　<input type="checkbox" name="category.isPhoto" class="check" />　　<span id="addResult" style="color:red;"></span>
            			<br/><input type="button" value="添加类别" class="submit" />
            		</form>
            	</div>
            	<div id="list">
            		<table cellpadding="0"  cellspacing="1">
            		<tr><td>类别 ID</td><td>类别名称</td><td>是否是图片类</td><td>修改</td><td>删除</td></tr>
            		<c:forEach items="${list}" var="category">
            			<tr>
            				<td>${category.cid }</td>
            				<td>${category.cname }</td>
            				<c:choose>
            					<c:when test="${category.isPhoto==1}">
            						<td><input type="checkbox" checked="checked" readonly="readonly" disabled="disabled" /></td>	
            					</c:when>
            					<c:otherwise>
            						<td><input type="checkbox" readonly="readonly" /></td>	
            					</c:otherwise>
            				</c:choose>
            				
            				<td><a href="javascript:;" class="update">修改</a></td>
            				<td><a href="javascript:;" class="delete">删除</a></td>
            			</tr>
            		</c:forEach>
            		</table>
            	</div>
            </div>
        </div>
	<jsp:include page="include/footer.jsp" />
  </body>
</html>
